﻿/*
输入：
5 5
0 0 0 0 0 
0 1 0 1 0
0 1 1 1 0
0 1 1 1 0
0 0 0 0 0
输出：
14
*/
// N行M列
string[] NMArr = Console.ReadLine().Split(" ");
int N = int.Parse(NMArr[0]);
int M = int.Parse(NMArr[1]);

// 填充map
int[,] map = new int[N, M];
for (int i = 0; i < N; i++)
{
    string[] line = Console.ReadLine().Split(" ");
    for (int j = 0; j < M; j++)
    {
        map[i, j] = int.Parse(line[j]);
    }
}


int node = 0; // 陆地面积
int near = 0; // 相邻
for (int i = 0; i < N; i++)
{
    for (int j = 0; j < M; j++)
    {
        if (map[i, j] == 1) node++;
        else continue;
        
        // 有左邻
        if (j > 0 && map[i, j - 1] == 1) near++;
        // 有上邻
        if (i > 0 && map[i - 1, j] == 1) near++;
    }
}
Console.WriteLine(4*node-2*near);